#include "init.h"


void init(char *title)
{
	if (SDL_Init(SDL_INIT_VIDEO ) < 0)
	{
		printf("Could not initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}

	jeu.screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32 , SDL_HWSURFACE|SDL_DOUBLEBUF);

    if (jeu.screen == NULL)
        {
            printf("Couldn't set screen mode to %d x %d: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
            exit(1);
        }
	SDL_WM_SetCaption(title, NULL);
	SDL_ShowCursor(SDL_DISABLE);


	/* Initialise SDL_Mixer */
    /* open 44.1KHz, signed 16bit, system byte order,
           stereo audio, using 1024 byte chunks */
    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024)==-1) {
        printf("Mix_OpenAudio: %s\n", Mix_GetError());
        exit(1);
    }

    /* Définit le nombre de channels à mixer */
    Mix_AllocateChannels(32);

}


void loadGame(void)
{

    map.x[0]=0;
    map.y[0]=0;
    map.background[0] = loadImage("graphics/sol.png");

    map.x[1]=0;
    map.y[1]=0;
    map.background[1] = loadImage("graphics/sour.png");

    map.x[2]=0;
    map.y[2]=0;
    map.background[2] = loadImage("graphics/ciel.png") ;


/*
    obs.obstacle[0] = loadImage("feu.bmp");
    obs.x[0] = 700 ;
    obs.y[0] = 490;
*/

     //On charge la musique
    loadSong("music/fond.mp3");
}



void cleanup()
{

	if (map.background[0] != NULL)
	{
		SDL_FreeSurface(map.background[0]);
	}

    /* On libère la chanson */
    if ( jeu.musique != NULL )
        Mix_FreeMusic(jeu.musique);

	// Quitte SDL_Mixer et décharge la mémoire
    Mix_CloseAudio();
    Mix_Quit();
	SDL_Quit();

}


